home *** CD-ROM | disk | FTP | other *** search
/ PC-Blue - MS DOS Public Domain Library / PC-Blue MS-DOS Public Domain Library - NYACC.iso / vol177 / public.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1986-11-25  |  15.3 KB  |  553 lines

  1. PROGRAM public_domain;
  2. { This program was written to  ease my task of Librarian of the Melbourne,
  3.   Australia, P-C  User`s Group.  For further details refer to the .DOC file
  4.   which should also be on this disk.   It is hereby placed into the Public
  5.   Domain on the strict understanding that it will not be used for commercial
  6.   gain.        David L. Jitts
  7.                24 Regent Street, East Brighton, 3187.
  8.                AUSTRALIA.  }
  9.  
  10.  
  11.                      {  MAIN DECLARATIONS. }
  12.  
  13. CONST
  14. title1 = 'MELBOURNE P-C USER`S GROUP';       {Title on Disk Labels}
  15. title2 = ' Public Domain Software';          {        ditto       }
  16. label_printer = 2;           {i.e. LPT2: If both printers are the same then}
  17. paper_printer = 1;           {program will prompt user to change paper type}
  18. width = 42;               {Label width pitch = 42 chars.}
  19. lab_length = 9;           {Label length pitch = 9 print lines}
  20. drive = 'B:';             {Drive for disk file if /D parameter switch
  21.                            has been included in command line }
  22.  
  23. TYPE
  24. vol_type  = STRING[15];
  25. line_type = STRING[80];
  26. data_type = STRING[25];
  27. pointr = ^labl;
  28. labl  = RECORD
  29.             volume    : vol_type;
  30.             order_no  : INTEGER;
  31.             next_lab  : pointr;
  32.           END;
  33. toe    = ^buyer;
  34. buyer  = RECORD
  35.             name     : data_type;
  36.             adres1   : data_type;
  37.             adres2   : data_type;
  38.             adres3   : data_type;
  39.             orderno  : INTEGER;
  40.             next_buy : toe;
  41.           END;
  42. datestr = STRING[8];
  43.  
  44. VAR
  45. library : vol_type;
  46. order, X : INTEGER;
  47. buylist, buytail : toe;
  48. lablist, labtail : pointr;
  49. bold_on, bold_off : STRING[2];
  50. pline : ARRAY[1..9] OF line_type;
  51. blank_line : line_type;
  52. disk_count : INTEGER;
  53. anykey : CHAR;
  54. to_disk : BOOLEAN;
  55.  
  56.          { ************************************************** }
  57.  
  58. FUNCTION date : datestr;
  59.  
  60. TYPE
  61.   regpack = RECORD
  62.               ax,bx,cx,dx,bp,si,di,ds,es,flags: INTEGER;
  63.             END;
  64.  
  65. VAR
  66.   recpack:       regpack;                {record for MsDos call}
  67.   month,day:     STRING[2];
  68.   year:          STRING[4];
  69.   dx,cx:         INTEGER;
  70.  
  71. BEGIN
  72.   WITH recpack DO
  73.   BEGIN
  74.     ax := $2A SHL 8;
  75.   END;
  76.   MsDos(recpack);                        { call function }
  77.   WITH recpack DO
  78.   BEGIN
  79.     STR(cx,year);                    {convert to string}
  80.     STR(dx mod 256,day);                     { " }
  81.     STR(dx shr 8,month);                     { " }
  82.   END;
  83.   date := day+'-'+month+'-'+COPY(year,3,2);  {In British date format}
  84. END;   {of date}
  85.  
  86.               { ****************************************** }
  87.  
  88. PROCEDURE select_printer(lpt : INTEGER);
  89. { Selects which of LPT1 or LPT2 corresponds to LST}
  90.  
  91. BEGIN
  92. CASE  lpt   OF
  93.   1: BEGIN
  94.        MEM[0000:$408] := 188;
  95.        MEM[0000:$409] :=   3;
  96.        MEM[0000:$40A] := 193;
  97.        MEM[0000:$40B] :=   0;
  98.      END;
  99.   2: BEGIN
  100.        MEM[0000:$408] := 193;
  101.        MEM[0000:$409] :=   0;
  102.        MEM[0000:$40A] := 188;
  103.        MEM[0000:$40B] :=   3;
  104.      END;
  105.   ELSE  WRITE(CHR(7), 'ILLEGAL PRINTER');
  106. END;  {of CASE}
  107. END;  {of select_printer}
  108.  
  109.               { ****************************************** }
  110.  
  111.  
  112. PROCEDURE initialise;
  113.  
  114. BEGIN
  115. IF (ParamSTR(1) = '/D') OR (ParamStr(1) = '/d') THEN
  116.          to_disk := TRUE
  117.   ELSE   to_disk := FALSE;
  118. bold_on := CHR(27) + '!';           {Not used in this version}
  119. bold_off := CHR(27) + '"';          {        ditto           }
  120. order := 1;
  121. blank_line := '';
  122. FOR X := 1 TO width DO
  123.    blank_line := blank_line + ' ';
  124. FOR X := 1 TO lab_length DO
  125.    pline[X] := ' ';
  126. lablist := NIL;
  127. buylist := NIL;
  128. disk_count := 0;
  129. END;   {of initialise}
  130.  
  131.               {  ***************************************** }
  132.  
  133. PROCEDURE banner;
  134.  
  135.  
  136. BEGIN
  137. CLRSCR;
  138. GOTOXY(2,4); WRITELN('THE PUBLIC DOMAIN SOFTWARE LABELLER');
  139. WRITELN;
  140. WRITELN('     This program has the following built-in constants:');
  141. WRITELN('           Labels sent to LPT',label_printer,':');
  142. IF to_disk THEN
  143.     WRITELN('           Lists sent to disk on Drive ',drive)
  144.   ELSE
  145.     WRITELN('           Lists sent to LPT',paper_printer,':');
  146. WRITELN('           Labels set for 2 across the sheet.');
  147. WRITELN('           Label width pitch  = ',width, ' characters');
  148. WRITELN('           Label length pitch =  ', lab_length, ' print lines');
  149. WRITELN;
  150. WRITELN('                Hit any Key to continue'); READ(Kbd, anykey);
  151. END;   {of banner}
  152.  
  153.  
  154.  
  155.               { ****************************************** }
  156.  
  157. PROCEDURE get_labls;
  158.  
  159. VAR
  160. new_labl : pointr;
  161. X, Y : INTEGER;
  162. in_labl : vol_type;
  163.  
  164. BEGIN
  165. X := 5; Y := 12;
  166. GOTOXY(10,9); WRITE('ENTER THE REQUIRED VOLUMES.');
  167.               WRITE('ENTER "*" TO ABORT ENTRIES');
  168. GOTOXY(10,10); WRITE('Rules: Max Vol Length 15, 4th character must be blank');
  169. in_labl := ' ';
  170. WHILE in_labl <> '*' DO
  171.  BEGIN
  172.   GOTOXY(X,Y);WRITE('? ');READ(in_labl);
  173.   IF in_labl = '*' THEN EXIT;      {Abort entry mode}
  174.   IF  (LENGTH(in_labl) > 15) OR (COPY(in_labl, 4,1) <> ' ') THEN
  175.      BEGIN
  176.         WRITE(CHR(7));   {Beep, erase and loop if it doesn`t match the rules}
  177.         GOTOXY(X,Y);WRITE('                    ');
  178.      END
  179.    ELSE                 {Process  the entry}
  180.      BEGIN
  181.        disk_count := disk_count + 1;
  182.        NEW(new_labl);
  183.        WITH new_labl^ DO
  184.          BEGIN
  185.            volume  := in_labl;
  186.            order_no := order;
  187.            next_lab :=  NIL;
  188.            IF lablist = NIL THEN
  189.                lablist := new_labl
  190.              ELSE labtail^.next_lab := new_labl;
  191.          END;  {of WITH new_labl}
  192.        labtail := new_labl;
  193.        in_labl := ' ';
  194.        X := X + 18;
  195.        IF X > 70 THEN
  196.          BEGIN
  197.            Y := Y + 1;
  198.            X := 5;
  199.           END;
  200.       END;  {of IF in_labl}
  201.    END;  {of WHILE}
  202. END;   {of get_labls}
  203.  
  204.              { ********************************************* }
  205.  
  206. PROCEDURE get_buyer;
  207.  
  208. VAR
  209. newbuyer    : toe;
  210. in_name     : data_type;
  211. in_adres1   : data_type;
  212. in_adres2   : data_type;
  213. in_adres3   : data_type;
  214. reply, answer    : CHAR;
  215. Y : INTEGER;
  216.  
  217. FUNCTION in_data : data_type;
  218.  
  219. LABEL loop;
  220.  
  221. VAR
  222. response : STRING[26];
  223.  
  224. BEGIN
  225. response := '';
  226. loop: GOTOXY(25,Y); READLN(response);
  227.       IF LENGTH(response) > 25 THEN
  228.         BEGIN
  229.            WRITE(CHR(7));
  230.            GOTOXY(25,Y);ClrEol;
  231.            GOTOXY(50,Y); WRITE(CHR(27),'- No entries past here');
  232.            GOTO loop;
  233.          END;
  234. in_data := response;
  235. Y := Y + 1;
  236. END;  {of FUNCTION}
  237.  
  238. BEGIN
  239. reply := ' ';
  240. WHILE reply <> 'Y' DO
  241.   BEGIN
  242.     CLRSCR;
  243.     GOTOXY(10,2); WRITE('PROCESSING ORDER No.: ', order);
  244.     GOTOXY(50,4); WRITE(CHR(27),'- No entries past here');
  245.     Y := 4;
  246.     GOTOXY(10,Y); WRITE('Buyer`s Name: ');in_name := in_data;
  247.     GOTOXY(10,Y); WRITE('Address    1: ');in_adres1 := in_data;
  248.     GOTOXY(10,Y); WRITE('           2: ');in_adres2 := in_data;
  249.     GOTOXY(10,Y); WRITE('           3: ');in_adres3 := in_data;
  250.     WHILE NOT (reply IN ['Y','N']) DO
  251.       BEGIN
  252.          GOTOXY(10,9); WRITE('Above Entries OK? Y/N ');READ(Kbd, reply);
  253.          reply := UPCASE(reply);
  254.          IF NOT (reply IN ['Y','N']) THEN WRITE(CHR(7));
  255.       END;
  256.     IF reply = 'Y' THEN
  257.       BEGIN
  258.         GOTOXY(10,9);WRITE('                     ');
  259.         NEW(newbuyer);
  260.         WITH newbuyer^ DO
  261.           BEGIN
  262.             name   := in_name;
  263.             adres1 := in_adres1;
  264.             adres2 := in_adres2;
  265.             adres3 := in_adres3;
  266.             orderno := order;
  267.             next_buy :=  NIL;
  268.             IF buylist = NIL THEN
  269.                  buylist := newbuyer
  270.             ELSE
  271.                 buytail^.next_buy := newbuyer;
  272.           END;   {of WITH newbuyer}
  273.           buytail := newbuyer;
  274.        END
  275.      ELSE get_buyer;
  276.   END;  {of WHILE reply}
  277.   get_labls;
  278.   CLRSCR;
  279.   answer := ' ';
  280.   WHILE NOT (answer IN ['Y','N']) DO
  281.     BEGIN
  282.       GOTOXY(10,10);WRITE('Another Order ? Y/N '); READ(Kbd, answer);
  283.       answer := UPCASE(answer);
  284.       IF NOT (answer IN ['Y','N']) THEN WRITE(CHR(7));
  285.     END;
  286.   IF answer = 'Y' THEN
  287.     BEGIN
  288.        order := order + 1;
  289.        get_buyer;
  290.     END;   {of IF reply}
  291. END;  {of get_buyer}
  292.  
  293.            { ******************************************* }
  294.  
  295. PROCEDURE sortlabls;
  296.  
  297. VAR
  298. unfinished : BOOLEAN;
  299. temp_vol : vol_type;
  300. finger : pointr;
  301.  
  302. BEGIN
  303. unfinished := TRUE;
  304. WHILE  unfinished DO
  305.    BEGIN
  306.       finger := lablist;
  307.       unfinished := FALSE;
  308.       while finger^.next_lab <> NIL do
  309.          begin
  310.            if (finger^.volume > finger^.next_lab^.volume) THEN
  311.              BEGIN
  312.                temp_vol := finger^.next_lab^.volume;
  313.                finger^.next_lab^.volume := finger^.volume;
  314.                finger^.volume  := temp_vol;
  315.                unfinished := true;
  316.              END;
  317.              finger := finger^.next_lab;
  318.           END; {WHILE finger}
  319.     END; {while unfinished}
  320. END;
  321.  
  322.    { ***************************************************** }
  323.  
  324. PROCEDURE print_plines;
  325.  
  326. VAR
  327. X : INTEGER;
  328.  
  329. BEGIN
  330. FOR X := 1 TO lab_length DO
  331.   BEGIN
  332.      WRITELN(LST, pline[X]);
  333.      pline[X] := ' ';
  334.   END; {of FOR}
  335. END;   {of print_plines}
  336.  
  337.               { ******************************************* }
  338.  
  339. PROCEDURE print_mail_labls;
  340.  
  341. VAR
  342. next : toe;
  343. refer : data_type;
  344. left : BOOLEAN;
  345. margin : INTEGER;
  346. order_str : STRING[4];
  347.  
  348. BEGIN
  349. next := buylist;
  350. left := TRUE;                     {start on the left}
  351. WHILE next <> NIL DO
  352.   BEGIN
  353.      WITH next^ DO
  354.        BEGIN
  355.           STR(orderno, order_str);
  356.           refer := '   Ref: ' + date  + ' #' + order_str;
  357.           IF left THEN BEGIN
  358.              pline[1] := name;
  359.              pline[2] := adres1;
  360.              pline[3] := adres2;
  361.              pline[4] := adres3;
  362.              pline[6] := refer;
  363.              FOR X := 1 TO lab_length DO
  364.               BEGIN
  365.                  pline[X] := pline[X] + blank_line;
  366.                  DELETE(pline[X],width,width);
  367.               END;  {of FOR X}
  368.            END   {of IF left}
  369.           ELSE BEGIN
  370.              pline[1] := pline[1] + name;
  371.              pline[2] := pline[2] + adres1;
  372.              pline[3] := pline[3] + adres2;
  373.              pline[4] := pline[4] + adres3;
  374.              pline[6] := pline[6] + refer;
  375.            END;  {of ELSE}
  376.           next := next_buy;
  377.           IF NOT left THEN print_plines;
  378.           left := NOT left;          {i.e. swap position flag}
  379.         END;   {of WITH next^}
  380.    END;   {of WHILE next}
  381. IF NOT left THEN print_plines;       {in case there was an odd number}
  382. END;   {of print_mail_labels}
  383.  
  384.            { ********************************************* }
  385.  
  386. PROCEDURE print_disk_labls;
  387.  
  388. VAR
  389. next : pointr;
  390. refer : data_type;
  391. left : BOOLEAN;
  392. margin : INTEGER;
  393. order_str : STRING[4];
  394.  
  395. BEGIN
  396. next := lablist;
  397. left := TRUE;
  398. WHILE next <> NIL DO
  399.   BEGIN
  400.      WITH next^ DO
  401.        BEGIN
  402.           STR(order_no, order_str);
  403.           refer := '   Ref: ' + date  + ' #' + order_str;
  404.           IF left THEN BEGIN
  405.              pline[1] := title1;
  406.              pline[2] := title2;
  407.              pline[4] := 'Volume: ' + volume;
  408.              pline[6] := refer;
  409.              FOR X := 1 to 6 DO BEGIN
  410.                  pline[X] := pline[X] + blank_line;
  411.                  DELETE(pline[X],width,width);
  412.              END;  {of FOR X}
  413.            END   {of IF left}
  414.           ELSE BEGIN
  415.              pline[1] := pline[1] + title1;
  416.              pline[2] := pline[2] + title2;
  417.              pline[4] := pline[4] + 'Volume: ' + volume;
  418.              pline[6] := pline[6] + refer;
  419.            END;  {of ELSE}
  420.           next := next_lab;
  421.           IF NOT left THEN print_plines;
  422.           left := NOT left;          {i.e. swap position flag}
  423.         END;   {of WITH next^}
  424.    END;   {of WHILE next}
  425. IF NOT left THEN print_plines;       {in case there was an odd number}
  426. END;    {of print_disk)labls}
  427.  
  428.          { ************************************************** }
  429.  
  430. PROCEDURE print_buyers_list;
  431.  
  432. VAR
  433. lab_ptr : pointr;
  434. buy_ptr : toe;
  435. line, page_no, current_order, colum :  INTEGER;
  436. out_put : TEXT;
  437. out_file : STRING[13];
  438. lpt_str :  STRING[1];
  439.  
  440. PROCEDURE header;
  441.  
  442. BEGIN
  443.   WRITELN(out_put,'    RECORD OF PUBLIC DOMAIN SOFTWARE SHIPMENT');
  444.   WRITELN(out_put,'    -----------------------------------------');
  445.   WRITE(out_put,'                 Date: ', date);
  446.   WRITE(out_put,'   Page No: ', page_no);
  447.   IF disk_count <> 0 THEN BEGIN
  448.        WRITELN(out_put, '     Total Disks used = ', disk_count);
  449.        disk_count := 0;
  450.     END
  451.    ELSE   WRITELN(out_put);
  452.   WRITELN(out_put);
  453.   page_no := page_no + 1;
  454.   line := 6;
  455. END;   {of header}
  456.  
  457.  
  458. BEGIN
  459. IF to_disk THEN
  460.     BEGIN
  461.        CLRSCR;
  462.        WRITE(#7);
  463.        GOTOXY(10,10);WRITELN('INSERT DISK INTO DRIVE ',drive);
  464.        GOTOXY(10,11);WRITELN('Then hit any key');
  465.        REPEAT UNTIL KeyPressed;
  466.        out_file := drive + date + '.PUB';
  467.     END
  468.  ELSE
  469.     BEGIN
  470.       select_printer(paper_printer);
  471.       STR(paper_printer,lpt_str);
  472.       out_file := 'LPT' + lpt_str;
  473.     END;
  474. ASSIGN(out_put, out_file);
  475. REWRITE(out_put);
  476. buy_ptr := buylist;
  477. page_no := 1;
  478. header;
  479. WHILE buy_ptr <> NIL DO
  480.   BEGIN
  481.      WITH buy_ptr^ DO
  482.        BEGIN
  483.           IF line > 56  THEN
  484.              BEGIN
  485.                 page_no := page_no + 1;
  486.                 header;
  487.                 WRITELN(out_put, CHR(12));
  488.              END;   {of IF line}
  489.           WRITELN(out_put,'Order No: ', orderno);
  490.           WRITELN(out_put, '    ',name);
  491.           WRITELN(out_put, '    ',adres1);
  492.           WRITELN(out_put, '    ',adres2);
  493.           WRITELN(out_put, '    ',adres3);
  494.           current_order := orderno;
  495.           buy_ptr := next_buy;
  496.           line := line + 5;
  497.        END;
  498.      WRITELN(out_put);
  499.      colum := 1;
  500.      lab_ptr := lablist;
  501.      WHILE lab_ptr <> NIL DO
  502.       BEGIN
  503.         IF lab_ptr^.order_no = current_order THEN
  504.            BEGIN
  505.              WRITE(out_put, lab_ptr^.volume,' ':(17 - LENGTH(lab_ptr^.volume)));
  506.              colum := colum + 1;
  507.              IF  colum > 4 THEN
  508.                 BEGIN
  509.                   WRITELN(out_put);
  510.                   line := line + 1;
  511.                   colum := 1;
  512.                 END;  {of IF colum}
  513.            END;   {of IF lab_ptr^}
  514.         lab_ptr := lab_ptr^.next_lab;
  515.       END;   {of WHILE lab_ptr}
  516.       WRITELN(out_put); WRITELN(out_put); line := line + 2;
  517. END;    {of WHILE buy_ptr}
  518. WRITELN(out_put);                  {Empty buffer and eject}
  519. WRITELN(out_put, CHR(12));
  520. IF to_disk THEN
  521.      CLOSE(out_put);
  522. END;   {of print_buyerslist}
  523.  
  524.          { ************************************************** }
  525.  
  526. BEGIN  {Main Program}
  527.   initialise;
  528.   banner;
  529.   get_buyer;
  530.   CLRSCR;
  531.   sortlabls;
  532.   WRITE(CHR(7));
  533.   GOTOXY(10,10);WRITELN('INSTALL LABELS INTO LPT',label_printer);
  534.   IF (label_printer <> paper_printer) AND (NOT to_disk) THEN
  535.     BEGIN
  536.       GOTOXY(10,12);
  537.       WRITELN('INSTALL PAPER INTO LPT',paper_printer);
  538.     END;
  539.   GOTOXY(10,14);WRITELN('GET THE PRINTER/S READY.');
  540.   GOTOXY(10,17);WRITELN('Hit any key when ready. ');READ(Kbd, anykey);
  541.   select_printer(label_printer);
  542.   print_mail_labls;
  543.   print_disk_labls;
  544.   IF (label_printer = paper_printer) AND (NOT to_disk) THEN
  545.     BEGIN
  546.       CLRSCR;
  547.       WRITE(CHR(7));
  548.       GOTOXY(10,10);WRITELN('INSTALL PAPER INTO LPT',label_printer);
  549.       WRITE('          Hit any key when ready. ');READ(Kbd, anykey);
  550.     END;   {of IF label_printer}
  551.   print_buyers_list;
  552. END.  {of Main Program}
  553.